import {getSwiper, getNavBar, getFloor} from '../../service/home';

Page({
  data: {
    swiperList: [],
    navBarList: [],
    floorList: []
  },
  onLoad: function() {
    this.pageInit();
  },
  async pageInit() {
    // 获取轮播图数据
    let swiper = await getSwiper();
    let swiperList = swiper.data.message;
    swiperList.forEach(v => v['navigator_url'] = v['navigator_url'].replace(/main/g, "goods_detail"));
    //获取导航数据 
    let navBar = await getNavBar();

    // 获取楼层数据
    let floor = await getFloor(); 
    let floorList = floor.data.message;
    floorList.forEach(v1 => {
      v1.product_list.forEach(v2 => {
        v2['navigator_url'] = v2['navigator_url'].replace('/goods_list', '/goods_list/goods_list');
      })
    })

    this.setData({
      swiperList,
      navBarList: navBar.data.message,
      floorList
    })
  }
})
